package shuashuami.hb.com.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.model.CPlatform;

/**
 * Created by Administrator on 2017/6/20.
 */

public class CHallPlatformAdatper extends BaseAdapter {
    private LayoutInflater inflater;
    private List<CPlatform> list;
    private Context con;

    public CHallPlatformAdatper(List<CPlatform> list, Context context) {
        this.con = context;
        inflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        if (null != list) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CSubordinateViewHoler viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.chall_platform_menu_tiems, null);
            viewHolder = new CSubordinateViewHoler();
            viewHolder.img = (ImageView) convertView.findViewById(R.id.img_chall_platform_menu_xuanze);
            viewHolder.tvName = (TextView) convertView.findViewById(R.id.tv_chall_platform_menu_name);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (CSubordinateViewHoler) convertView.getTag();
        }
        CPlatform content = list.get(position);
        viewHolder.tvName.setText(content.getName());
        if (content.isChoose()) {
            viewHolder.img.setVisibility(View.VISIBLE);
            viewHolder.tvName.setTextColor(con.getResources().getColor(R.color.app_main));
        } else {
            viewHolder.tvName.setTextColor(Color.BLACK);
            viewHolder.img.setVisibility(View.GONE);
        }
        return convertView;
    }

    class CSubordinateViewHoler {
        public ImageView img;
        public TextView tvName;
    }


}




